home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / generic.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  6KB  |  223 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw/generic.c
  4.  
  5.   Some general purpose functions used by many video drivers.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *videoram;
  15. size_t videoram_size;
  16. unsigned char *colorram;
  17. unsigned char *spriteram;    /* not used in this module... */
  18. unsigned char *spriteram_2;    /* ... */
  19. unsigned char *spriteram_3;    /* ... */
  20. unsigned char *buffered_spriteram;    /* not used in this module... */
  21. unsigned char *buffered_spriteram_2;    /* ... */
  22. size_t spriteram_size;    /* ... here just for convenience */
  23. size_t spriteram_2_size;    /* ... here just for convenience */
  24. size_t spriteram_3_size;    /* ... here just for convenience */
  25. unsigned char *flip_screen;    /* ... */
  26. unsigned char *flip_screen_x;    /* ... */
  27. unsigned char *flip_screen_y;    /* ... */
  28. unsigned char *dirtybuffer;
  29. struct osd_bitmap *tmpbitmap;
  30.  
  31.  
  32.  
  33. /***************************************************************************
  34.  
  35.   Start the video hardware emulation.
  36.  
  37. ***************************************************************************/
  38. int generic_vh_start(void)
  39. {
  40.     dirtybuffer = 0;
  41.     tmpbitmap = 0;
  42.  
  43.     if (videoram_size == 0)
  44.     {
  45. logerror("Error: generic_vh_start() called but videoram_size not initialized\n");
  46.         return 1;
  47.     }
  48.  
  49.     if ((dirtybuffer = malloc(videoram_size)) == 0)
  50.         return 1;
  51.     memset(dirtybuffer,1,videoram_size);
  52.  
  53.     if ((tmpbitmap = osd_new_bitmap(Machine->drv->screen_width,Machine->drv->screen_height,Machine->scrbitmap->depth)) == 0)
  54.     {
  55.         free(dirtybuffer);
  56.         return 1;
  57.     }
  58.  
  59.     return 0;
  60. }
  61.  
  62.  
  63. int generic_bitmapped_vh_start(void)
  64. {
  65.     if ((tmpbitmap = osd_new_bitmap(Machine->drv->screen_width,Machine->drv->screen_height,Machine->scrbitmap->depth)) == 0)
  66.     {
  67.         return 1;
  68.     }
  69.  
  70.     return 0;
  71. }
  72.  
  73.  
  74. /***************************************************************************
  75.  
  76.   Stop the video hardware emulation.
  77.  
  78. ***************************************************************************/
  79. void generic_vh_stop(void)
  80. {
  81.     free(dirtybuffer);
  82.     osd_free_bitmap(tmpbitmap);
  83.  
  84.     dirtybuffer = 0;
  85.     tmpbitmap = 0;
  86. }
  87.  
  88. void generic_bitmapped_vh_stop(void)
  89. {
  90.     osd_free_bitmap(tmpbitmap);
  91.  
  92.     tmpbitmap = 0;
  93. }
  94.  
  95.  
  96. /***************************************************************************
  97.  
  98.   Draw the game screen in the given osd_bitmap.
  99.   To be used by bitmapped games not using sprites.
  100.  
  101. ***************************************************************************/
  102. void generic_bitmapped_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  103. {
  104.     if (full_refresh)
  105.         copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  106. }
  107.  
  108.  
  109. READ_HANDLER( videoram_r )
  110. {
  111.     return videoram[offset];
  112. }
  113.  
  114. READ_HANDLER( colorram_r )
  115. {
  116.     return colorram[offset];
  117. }
  118.  
  119. WRITE_HANDLER( videoram_w )
  120. {
  121.     if (videoram[offset] != data)
  122.     {
  123.         dirtybuffer[offset] = 1;
  124.  
  125.         videoram[offset] = data;
  126.     }
  127. }
  128.  
  129. WRITE_HANDLER( colorram_w )
  130. {
  131.     if (colorram[offset] != data)
  132.     {
  133.         dirtybuffer[offset] = 1;
  134.  
  135.         colorram[offset] = data;
  136.     }
  137. }
  138.  
  139.  
  140.  
  141. READ_HANDLER( spriteram_r )
  142. {
  143.     return spriteram[offset];
  144. }
  145.  
  146. WRITE_HANDLER( spriteram_w )
  147. {
  148.     spriteram[offset] = data;
  149. }
  150.  
  151. READ_HANDLER( spriteram_2_r )
  152. {
  153.     return spriteram_2[offset];
  154. }
  155.  
  156. WRITE_HANDLER( spriteram_2_w )
  157. {
  158.     spriteram_2[offset] = data;
  159. }
  160.  
  161. /* Mish:  171099
  162.  
  163.     'Buffered spriteram' is where the graphics hardware draws the sprites
  164. from private ram that the main CPU cannot access.  The main CPU typically
  165. prepares sprites for the next frame in it's own sprite ram as the graphics
  166. hardware renders sprites for the current frame from private ram.  Main CPU
  167. sprite ram is usually copied across to private ram by setting some flag
  168. in the VBL interrupt routine.
  169.  
  170.     The reason for this is to avoid sprite flicker or lag - if a game
  171. is unable to prepare sprite ram within a frame (for example, lots of sprites
  172. on screen) then it doesn't trigger the buffering hardware - instead the
  173. graphics hardware will use the sprites from the last frame. An example is
  174. Dark Seal - the buffer flag is only written to if the CPU is idle at the time
  175. of the VBL interrupt.  If the buffering is not emulated the sprites flicker
  176. at busy scenes.
  177.  
  178.     Some games seem to use buffering because of hardware constraints -
  179. Capcom games (Cps1, Last Duel, etc) render spriteram _1 frame ahead_ and
  180. buffer this spriteram at the end of a frame, so the _next_ frame must be drawn
  181. from the buffer.  Presumably the graphics hardware and the main cpu cannot
  182. share the same spriteram for whatever reason.
  183.  
  184.     Sprite buffering & Mame:
  185.  
  186.     To use sprite buffering in a driver use VIDEO_BUFFERS_SPRITERAM in the
  187. machine driver.  This will automatically create an area for buffered spriteram
  188. equal to the size of normal spriteram.
  189.  
  190.     Spriteram size _must_ be declared in the memory map:
  191.  
  192.     { 0x120000, 0x1207ff, MWA_BANK2, &spriteram, &spriteram_size },
  193.  
  194.     Then the video driver must draw the sprites from the buffered_spriteram
  195. pointer.  The function buffer_spriteram_w() is used to simulate hardware
  196. which buffers the spriteram from a memory location write.  The function
  197. buffer_spriteram(unsigned char *ptr, int length) can be used where
  198. more control is needed over what is buffered.
  199.  
  200.     For examples see darkseal.c, contra.c, lastduel.c, bionicc.c etc.
  201.  
  202. */
  203.  
  204. WRITE_HANDLER( buffer_spriteram_w )
  205. {
  206.     memcpy(buffered_spriteram,spriteram,spriteram_size);
  207. }
  208.  
  209. WRITE_HANDLER( buffer_spriteram_2_w )
  210. {
  211.     memcpy(buffered_spriteram_2,spriteram_2,spriteram_2_size);
  212. }
  213.  
  214. void buffer_spriteram(unsigned char *ptr,int length)
  215. {
  216.     memcpy(buffered_spriteram,ptr,length);
  217. }
  218.  
  219. void buffer_spriteram_2(unsigned char *ptr,int length)
  220. {
  221.     memcpy(buffered_spriteram_2,ptr,length);
  222. }
  223.